package com.example.controller;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.fastjson.JSON;
import com.example.config.GlobalException;
import com.example.entity.Datasource;
import com.example.entity.EduTeacher;
import com.example.mapper.EntityDao;
import com.example.service.ProviderFeign;
import com.example.service.RoleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/consumes")
public class ProviderTeacher {
    @Autowired
    private ProviderFeign providerFeign;
    @Autowired
    private Environment environment;
    @Autowired
    private Datasource datasource;
    @GetMapping("/consumeteachers")
    @SentinelResource(value = "consumeblock",blockHandler = "consumeHandle")
    public String consumeTeacher(HttpServletRequest request, HttpServletResponse response) throws GlobalException {
        String token= request.getHeader("token");
        String teachers = providerFeign.teachers();
        return teachers;
    }

    public String consumeHandle(HttpServletRequest request, BlockException blockException){
        String teachers = providerFeign.teachers();
         return teachers;
    }

    @GetMapping("/user")
    public String get(){
        System.out.println(datasource.getDriver());
        System.out.println(datasource.getUrl());
        System.out.println(datasource.getUsername());
        System.out.println(datasource.getPassword());
        return "get";
    }
    @PutMapping("/user")
    public String put(){
        System.out.println(environment.getProperty("spring.application.name"));
        return "put";
    }
    @PostMapping("/user")
    public String post(){
        return "post";
    }
    @DeleteMapping("/user")
    public String delete(){
        return "delete";
    }

    @Autowired
    private EntityDao entityDao;
    @Autowired
    private RoleServiceImpl roleService;

      @GetMapping("/async")
      public String async(){
          String s = null;
          try {
              s = roleService.insertTest();
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          return "插入成功";
      }
}
